package com.zh.note.huawei.twohundred.分割数组的最大差值;

import java.util.Arrays;
import java.util.Scanner;

/**
 * https://dream.blog.csdn.net/article/details/132966300
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String input = sc.nextLine();
        int[] arr = Arrays.stream(input.split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] newArr = new int[arr.length];
        System.arraycopy(arr, 0, newArr, 0, arr.length);
        int maxDiffer = -1;
        for (int i = 1; i < newArr.length; i++) {
            int[] left = new int[i];
            int[] right = new int[newArr.length - i];
            System.arraycopy(newArr, 0, left, 0, i);
            System.arraycopy(newArr, i, right, 0, newArr.length - i);

            int leftSum = Arrays.stream(left).sum();
            int rightSum = Arrays.stream(right).sum();
            int abs = Math.abs(leftSum - rightSum);
            maxDiffer = Math.max(maxDiffer, abs);
        }
        System.out.println(maxDiffer);
    }
}
